<?php
session_start();
include_once('config.php');

if(@$_POST['guiykien']){
	if($_SESSION['date_end'] <= date('i')){
		$tc->guiykien($_POST['form'],$_POST['name'],$_POST['email'],$_POST['content'],$_SESSION['detail']);
		$_SESSION['date_start'] = date('i');
	}
	if(!@$_SESSION['date_start']) $_SESSION['date_start'] = date('i');
	$_SESSION['date_end'] = $_SESSION['date_start'] + 2;
}

if($_POST['popup']==123){
	$qr = "SELECT name,url_hinh,link,info FROM slider_banner WHERE `delete`=0 AND status=1 AND position_id=2 AND id=".$_POST['id'];
	$danxe = mysql_query($qr);
	$row = mysql_fetch_array($danxe);
	echo '<div id="popupContact"><img style="width:400px; float:left; margin-right:70px" src="upload/images/xe_intro/big_'.$row['url_hinh'].'" alt="'.$row['name'].'" /><div class="content"><a href="javascript:;" id="popupContactClose"><img src="images/Close.png" alt="" /></a><h2>'.$row['name'].'</h2><br /><p>'.$row['info'].'<p><a href="'.$row['link'].'" target="_blank"><img src="images/chitiet.gif" alt="" /></a></p></p></div></div><div id="backgroundPopup"></div>';
}
if($_POST['popup']==111){ /* hỏi */
    echo '<div id="popupContact"><div id="formykien">
	<h4 style="color:#FFF000; font-size:16px; margin-bottom:5px">Hỏi?</h4>
	<p><input type="text" name="name" value="Họ tên" maxlength="50" class="txt" /></p>
	<p><input type="text" name="email" value="Email" maxlength="50" class="txt" /></p>
	<p><textarea class="textarea" name="content"></textarea></p>
	<p><input type="button" name="btnSub" value="Gửi" class="btn" /><input type="button" name="btnCancel" value="Hủy" class="btn" /></p>
	<input type="hidden" name="id" value="'.$_POST['id'].'" /><input type="hidden" name="form" value="question" />
	</div></div><div id="backgroundPopup"></div>';
}
if($_POST['popup']==112){ /* tra loi */
    echo '<div id="popupContact"><div id="formykien">
	<h4 style="color:#FFF000; font-size:16px; margin-bottom:5px">Trả lời của bạn..</h4>
	<p><input type="text" name="name" value="Họ tên" maxlength="50" class="txt" /></p>
	<p><input type="text" name="email" value="Email" maxlength="50" class="txt" /></p>
	<p><textarea class="textarea" name="content"></textarea></p>
	<p><input type="button" name="btnSub" value="Gửi" class="btn" /><input type="button" name="btnCancel" value="Hủy" class="btn" /></p>
	<input type="hidden" name="id" value="'.$_SESSION['cauhoi'].'" /><input type="hidden" name="form" value="answers" />
	</div></div><div id="backgroundPopup"></div>';
}
if($_POST['popup']==258){ /* xem câu hỏi và trả lời */
	$qr = "SELECT id,name,content,date_create FROM question WHERE `delete`=0 AND status=1 AND id=".$_POST['id'];
	$cauhoi = mysql_query($qr);
	$row = mysql_fetch_array($cauhoi);
	$_SESSION['cauhoi']=$row['id'];
	$echo = '<div id="popupContact"><div id="content_3"><div id="xemcauhoi"><a href="javascript:;" id="popupContactClose"><img src="images/Close.png" alt="" /></a><h2>'.$row['name'].'</h2><br /><div>'.$row['content'].'<h3 style="color:#FF0; margin-top:15px">Trả lời</h3><span id="traloi"><img src="images/traloi.jpg" alt="trả lời" /></span>';
    $qr2 = mysql_query("SELECT name,content FROM answers WHERE `delete`=0 AND status=1 AND question_id='{$row['id']}' ORDER BY date_update DESC");
	while($row = mysql_fetch_array($qr2)){
		if($row['name'] != 'Admin')	$echo .= '<span><b style="color:#CCC">'.$row['name'].': </b>'.$row['content'].'</span>';
		else $echo .= '<span style="color:#C30"><b>'.$row['name'].': </b>'.$row['content'].'</span>';
	}
    $echo .= '</div></div></div><!--end content 3--></div><div id="backgroundPopup"></div>';
    echo $echo;
}
if(@$_POST['phantrang']){
	$page = $_POST['page'];
	$from = (($page - 1) * max_picture);
	$select = 'id,name,content,date_create';
	$table = 'question';
	$where = '`delete`=0 AND status=1';
	$limit = "LIMIT {$from},".max_picture;
	
	$hoi = $tc->list_item($select,$table,$where,$limit);
	if(mysql_num_rows($hoi) > 0){
		while($row = mysql_fetch_array($hoi)){
			$content = str_replace('<p>','',$row['content']);
			$content = str_replace('</p>','',$content);
			echo "<div class='item_cauhoi'><h3><a href='javascript:;' class='show_cauhoi {$row['id']}'>{$row['name']}</a> <span style='font-weight:100; font-size:13px; color:#666'> (".date('H:i | d/m/Y',strtotime($row['date_create'])).")</span></h3>
			<div><b style='color:#000'>Hỏi: </b>{$content}</div></div>";
		}
		mysql_free_result($hoi);
	}
	$phantrang = $tc->phantrang('javascript:;',$page,max_picture,'id',$table,$where,$limit);
	echo "<div class=\"phantrang\">{$phantrang}</div>";
}
if(@$_POST['ptxeco']){
	$page = $_POST['page'];
	$from = (($page - 1) * 4);
	$select = 'id,name,name_rewrite,url_hinh,description,date_create,menu_id';
	$table = 'info';
	$where = "`delete`=0 AND status=1 AND id<>'{$detail['id']}' AND menu_id LIKE '%,2,%'";
	$limit = "LIMIT {$from},4";
	
	$qr = $tc->list_item($select,$table,$where,$limit);
	while($row = mysql_fetch_array($qr)){
		$url_link = $tc->link_detail($row['menu_id']);
		($row['url_hinh']!= '') ? $url_hinh = url_hinh_xeco_thumbs.$row['url_hinh'] : $url_hinh='upload/no-image.jpg';
		$view .= "<div class=\"item\">
			<a href=\"{$url_link}{$row['name_rewrite']}.html\"><img src=\"{$url_hinh}\" alt=\"{$row['name']}\" />
			<h2>{$row['name']}</h2></a>
			<p>{$row['description']}</p>
			<div style=\"height:10px; clear:both\"></div>
		</div>";
	}
	mysql_free_result($qr);
	$phantrang = $tc->phantrang('javascript:;',$page,4,'id',$table,$where,$limit);
	$view .= "<div id=\"phantrang\">{$phantrang}</div>";
	echo $view;
}